<?php
namespace app\mqtt\validate;
use think\Validate;
class Msg extends Validate {
    //验证字段
    protected $rule = [
        'content' => ['require','number'],
        'chat_id' => ['require','number'],
        'send_account_id' => ['require','number'],
        'create_time' => ['require','number'],
        'accepted_account_id' => ['require'],
        'is_file' => ['require','number'],
        'file_name' => ['require'],
        'file_size' => ['require'],
        'file_type' => ['require'],
        'file_url' => ['require'],
        'msg_type' => ['require'],
        'id' => ['require','number'],
    ];
    //返回消息
    protected $message = [
        'content.require' => '内容必须',
        'content.number' => '内容不是数字',
        'chat_id.require' => '窗口id必须',
        'chat_id.number' => '窗口id不是数字',
        'send_account_id.require' => '发送账号id必须',
        'send_account_id.number' => '发送账号id不是数字',
        'create_time.require' => '创建时间必须',
        'create_time.number' => '创建时间不是数字',
        'accepted_account_id.require' => '接收用户必须',
        'is_file.require' => '是文件必须',
        'is_file.number' => '是文件不是数字',
        'file_name.require' => '文件名必须',
        'file_size.require' => '文件大小必须',
        'file_type.require' => '文件类型必须',
        'file_url.require' => '文件路径必须',
        'msg_type.require' => '普通文件必须',
        'id.require' => 'id必须',
        'id.number' => 'id不是数字',
    ];

    // except_id 场景
    public function sceneExcept_id(){
        return $this->only(['content','chat_id','send_account_id','create_time','accepted_account_id','is_file','file_name','file_size','file_type','file_url','msg_type']);
    }

    // only_id 场景
    public function sceneOnly_id(){
        return $this->only(['id']);
    }

    // only_chat_id 场景
    public function sceneOnly_chat_id(){
        return $this->only(['chat_id']);
    }

    // all_field 场景
    public function sceneAll_field(){
        return $this->only(['content','id','chat_id','send_account_id','create_time','accepted_account_id','is_file','file_name','file_size','file_type','file_url','msg_type']);
    }
}
